<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.48">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #a92500; min-height: 12.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #a92500}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #003dff}
span.s3 {color: #0049bf}
span.s4 {color: #a92500}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>SawDPW<span class="Apple-tab-span">	</span></b></span><b><span class="Apple-tab-span">	</span>super-efficient sawtooth oscillator with low aliasing</b></p>
<p class="p2"><br></p>
<p class="p1"><b>SawDPW.ar(freq, iphase, mul, add)</b></p>
<p class="p2"><br></p>
<p class="p1">A sawtooth oscillator using the "Differentiated Parabolic Wave" technique, which suppresses aliasing at a wide range of frequencies, yet is about 3 times as CPU-efficient as SuperCollider's <a href="SC://Saw"><span class="s2">Saw</span></a> ugen.<span class="Apple-converted-space"> </span></p>
<p class="p3"><br></p>
<p class="p1"><b>freq</b> - frequency in Hertz</p>
<p class="p1"><b>iphase </b>- initial phase offset, a value ranging from -1 to 1.</p>
<p class="p2"><br></p>
<p class="p1">It doesn't guarantee to be alias-free but sounds very good for most applications: e.g. at 44.1 kHz sample rate, aliasing can only be heard if the frequency goes over around 4 kHz. The technique is documented in Välimäki (2005) <i>Signal Processing Letters</i> 12(3) pages 214-217.</p>
<p class="p3"><br></p>
<p class="p1">See also: <a href="PulseDPW.html"><span class="s2">PulseDPW</span></a></p>
<p class="p2"><br></p>
<p class="p4"><br></p>
<p class="p5"><span class="s3">Server</span>.default = s = <span class="s3">Server</span>.internal;</p>
<p class="p5">s.boot</p>
<p class="p5">s.scope</p>
<p class="p4"><br></p>
<p class="p6">// Amplitude will be polled, move mouse to change frequency</p>
<p class="p5">{<span class="s3">var</span> x; x = <span class="s3">SawDPW</span>.ar(<span class="s3">MouseX.kr</span>(50, 2000, 1));<span class="s3">Amplitude</span>.ar(x, 0.2, 0.2).poll; x.madd(0.1).dup}.play</p>
<p class="p5">{<span class="s3">var</span> x; x = <span class="s3">SawDPW</span>.ar(<span class="s3">K2A</span>.ar(<span class="s3">MouseX.kr</span>(50, 2000, 1)));<span class="s3">Amplitude</span>.ar(x, 0.2, 0.2).poll; x.madd(0.1).dup}.play</p>
<p class="p4"><br></p>
<p class="p6">// Listen to these to compare aliasing characteristics</p>
<p class="p5">{<span class="s3">var</span> x; x = <span class="s3">SawDPW</span>.ar(<span class="s3">MouseX.kr</span>(50, 10000, 1).poll); x.madd(0.1).dup}.play</p>
<p class="p5">{<span class="s3">var</span> x; x = <span class="s3">Saw</span> <span class="Apple-converted-space">  </span>.ar(<span class="s3">MouseX.kr</span>(50, 10000, 1).poll); x.madd(0.1).dup}.play</p>
<p class="p5">{<span class="s3">var</span> x; x = <span class="s3">LFSaw</span> .ar(<span class="s3">MouseX.kr</span>(50, 10000, 1).poll); x.madd(0.1).dup}.play</p>
<p class="p4"><br></p>
<p class="p5">{<span class="s3">var</span> x; x = [<span class="s3">SawDPW</span>, <span class="s3">Saw</span>].collect(<span class="s3">_</span>.ar(<span class="s3">K2A</span>.ar(<span class="s3">MouseX.kr</span>(10, 20000, 1).poll))); <span class="s3">Amplitude</span>.ar(x[0], 0.2, 0.2).poll; x.madd(0.1)}.play</p>
<p class="p4"><br></p>
<p class="p6">// Efficiency comparisons:</p>
<p class="p5">~num = 100;</p>
<p class="p6">// scsynth on PPC Mac G4, idle around 2.1% CPU</p>
<p class="p6">// k-rate freq inputs</p>
<p class="p5">{<span class="s3">Saw</span> <span class="Apple-converted-space">  </span>.ar({exprand(50, 1000)}.dup(~num)).mean.dup}.play <span class="s4">// 30.7% CPU</span></p>
<p class="p5">{<span class="s3">SawDPW</span>.ar({exprand(50, 1000)}.dup(~num)).mean.dup}.play <span class="s4">// 12.4% CPU</span></p>
<p class="p5">{<span class="s3">LFSaw</span> .ar({exprand(50, 1000)}.dup(~num)).mean.dup}.play <span class="s4">//<span class="Apple-converted-space">  </span>7.0% CPU</span></p>
<p class="p4"><br></p>
</body>
</html>
